package com.hnl.action.user;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.HNLPageDispatch;
import com.hnl.core.aware.HNLAuthAware;
import com.hnl.core.aware.HNLTalentAware;
import com.hnl.core.aware.MiscTypeAware;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.UserDAO;
import com.hnl.to.User;
import com.hnl.to.wrapper.UserWrapper;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
public class DeleteConsultant extends HttpServlet implements HNLAuthAware,
		HNLTalentAware, MiscTypeAware, HNLPageDispatch {
	
	public static final Logger LOG = LoggerFactory.getLogger(DeleteConsultant.class);

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try{

			String delString = req.getParameter(ATTRIBUTE_DELETE_LIST);
			
			UserDAO userDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getUserDAO();
			String[] delLists = delString.split(",");
			
			for(String list:delLists){
				Integer uID=Integer.parseInt(list);
				userDAO.deleteUser(uID);
			}
			
			Collection<User> userCollection = userDAO.loadAllUser();
			Collection<UserWrapper> userWrapperCollection = new Vector<UserWrapper>();

			for (User user : userCollection) {
				UserWrapper newUserWrapper = new UserWrapper(user);
				newUserWrapper.getUserIDText();
				newUserWrapper.getModifiedUserIDText();
				userWrapperCollection.add(newUserWrapper);
			}

			PrintWriter writer = resp.getWriter();
			writer.println(JSONResponseUtil
					.getJSONObjectString(userWrapperCollection));

			//writer.println(JSONResponseUtil.getJSONObjectString(eduCollection));
		}catch(DAOException e) {
			LOG.error("Error to delete Activity", e);
		}
	}
	
	


}
